package com.lc.admin.web;

import com.lc.admin.base.ResponseResult;
import com.lc.admin.dto.DeptSaveDto;
import com.lc.admin.service.DeptService;
import com.lc.admin.vo.DeptSelectVo;
import com.lc.admin.vo.DeptTableVo;
import com.lc.admin.vo.UserVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

//@Api(tags="部门管理")
@RestController
@RequestMapping("/dept")
public class DeptWeb {

    @Autowired
    DeptService deptService;

//    @ApiOperation("查询多级部门列表")
    @GetMapping("/list")
    public ResponseResult<List<DeptTableVo>> findAll() {
        try {
            return ResponseResult.success(deptService.findAll());
        } catch (Exception e) {
            return ResponseResult.error(e.getMessage());
        }
    }

//    @ApiOperation("查询所有用户")
    @GetMapping("/user")
    public ResponseResult<List<UserVo>> findAllUser() {
        return ResponseResult.success(deptService.findAllUser());
    }

//    @ApiOperation("查询前两级部门")
    @GetMapping("/secondDept")
    public ResponseResult<List<DeptSelectVo>> findSecondDept() {
        return ResponseResult.success(deptService.findSecondDept());
    }

//    @ApiOperation("保存部门")
    @PostMapping("/save")
    public ResponseResult save(@RequestBody DeptSaveDto deptSaveDto) {
        deptService.save(deptSaveDto);
        return ResponseResult.success();
    }

//    @ApiOperation("删除部门")
    @DeleteMapping("/del/{id}")
    public ResponseResult save(@PathVariable Long id) {
        deptService.del(id);
        return ResponseResult.success();
    }
}
